/**
 *博尔信基础开发平台
 *<br> 版权声明：厦门博尔信软件有限公司版权所有,违者必究
 *<br> Copyright:  Copyright (c) 2012
 *<br> Company:pearlsoft
 *<br> @author 蒋勇华
 *<br> 2012-5-16
 *<br> @version 1.0
 *————————————————————————————————————
 *修改记录
 *    修改者：
 *    修改时间：
 *    修改原因：
 *——————————————————————————————————————
 */
package com.pearlsoft.webapp.rms.myres.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.pearlsoft.webapp.core.dao.RecrodRowMapper;
import com.pearlsoft.webapp.core.dataset.Record;
import com.pearlsoft.webapp.core.service.BaseSimpleJdbcService;

/**
 *描述： 
 *
 * 
 */
@Service
public class MyResService extends BaseSimpleJdbcService{
	private RecrodRowMapper myResRowMapper = MyResRowMapperHelper.myResRowMapper();
	private RecrodRowMapper myResHostRowMapper = MyResRowMapperHelper.myResHostRowMapper();

	
	public List<Record> getMyResList(String userId){
		String sql=" select resId,applyId,ownerId,resName,resDesc,startDate,endDate,status ,eName from rms_myres f  " +
				" where f.ownerId=:ownerId order by f.startDate ";
		Map<String,String> param = new HashMap<String,String>();
		param.put("ownerId", userId);
		return this.getBaseSimpleJdbcDao().query(sql, param, myResRowMapper );
	}
	
	
	public Record getById(String resId){
		String sql=" select resId,applyId,ownerId,resName,resDesc,startDate,endDate,status,eName  from rms_myres f  " +
					"where f.resId=:resId order by f.startDate";
		Map<String,String> param = new HashMap<String,String>();
		param.put("resId", resId);
		Record record = this.getBaseSimpleJdbcDao().queryOne(sql,param,myResRowMapper);
		if(record==null){
			return null;
		}
		String sqlHost="select  hostId,resId,hostName,hostDesc,hostIp,account,pwd,opsSeries,opsName,cups,memory,memoryunit,storage,storageunit,netcards  ";
		sqlHost = sqlHost +" from rms_myhost where resId=:resId";
		List<Record> hostList = this.getBaseSimpleJdbcDao().query(sqlHost, param, myResHostRowMapper);
		List<Map> tempList = new ArrayList<Map>(); 
		for( Record temp:hostList){
			tempList.add(temp.toMap());
		}
		if( tempList!=null && tempList.size()>0){
			record.setValue("hostList", tempList);
		}else{
			record.setValue("hostList", null);
		}
		return record;
	}
}
